package cn.handong.tool.controller;

import cn.handong.tool.pojo.TestAnnoReqVo;
import cn.handong.tool.service.AsyncTestService;
import cn.handong.tool.多线程.线程池.ThreeElementsVerifyManager;
//import com.handong.service.HelloService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@RestController
public class TestController {

//    @Autowired
//    HelloService helloService;
//
//    @GetMapping("/starter")
//    public String testStarter() {
//        String handong = helloService.sayHello("handong");
//        System.out.println(handong);
//        return handong;
//    }

    @Autowired
    AsyncTestService asyncTestService;

    @Autowired
    ThreeElementsVerifyManager threeElementsVerifyManager;

    @PostMapping("/test1")
    public String test1(@RequestBody @Valid TestAnnoReqVo reqVo){
        return "调用了 test1 "+" "+reqVo.getAuthNumber()+" "+reqVo.getCardNumber()+" "+reqVo.getMobilephone();
    }

    @GetMapping("/testasy")
    public void testasy() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            threeElementsVerifyManager.processThreeElementsVerify();
        }
    }
 
    @GetMapping("/test")
    public void test() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            asyncTestService.function1(); // 执行异步任务
//            asyncTestService.function2();
        }
 
//        asyncTestService.function1(); // 执行异步任务
//        asyncTestService.function2();
 
    }

    @Test
    public void testPool() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            asyncTestService.function1();
        }
    }
}